//
//  DHS2_OrderDetail_AddressCell.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/6/19.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHS2_OrderDetail_AddressCell.h"
#import "DHS2_OrderDetail_Address_LogisticsCell.h"

@interface DHS2_OrderDetail_AddressCell()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UIView *sixView;
@end

@implementation DHS2_OrderDetail_AddressCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"DHS2_OrderDetail_Address_LogisticsCell" bundle:nil] forCellReuseIdentifier:kDHS2_OrderDetail_Address_LogisticsCell];
}

- (NSArray *)logistics{
    if (!_logistics) {
        _logistics = [NSArray array];
    }
    return _logistics;
}

- (void)updateCell:(NSDictionary *)dic{
    if ([[dic objectForKey:@"need_fast"] boolValue]) {
        self.sixView.hidden = NO;
    }else{
        self.sixView.hidden = YES;
    }
    
    NSDictionary *receiver = [dic objectForKey:@"receiver"];
    self.nameLabel.text = [receiver objectForKey:@"contact"];
    self.addressLabel.text = [NSString stringWithFormat:@"%@%@%@%@",[receiver objectForKey:@"province"],[receiver objectForKey:@"city"],[receiver objectForKey:@"district"],[receiver objectForKey:@"address"]];
    self.phoneLabel.text = [receiver objectForKey:@"phone"];
    
    self.logistics = [dic objectForKey:@"logistics"];
    [self.tableView reloadData];
}

#pragma mark - tableview
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.logistics.count == 0) {
        return 1;
    }else{
        return self.logistics.count;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 30;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DHS2_OrderDetail_Address_LogisticsCell *cell = [tableView dequeueReusableCellWithIdentifier:kDHS2_OrderDetail_Address_LogisticsCell forIndexPath:indexPath];
    if (self.logistics.count == 0) {
        cell.tLabel.text = @"· 暂无物流信息";
    }else{
        cell.tLabel.text = @"· 物流信息";
    }
    return cell;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
